package day11;

public class Duration {
    // 1. int类型属性hour、min、sec
    private int hour;
    private int min;
    private int sec;

    // 2. 无参构造器
    public Duration() {
    }

    // 3. 三参构造器，对hour、min、sec进行初始化
    public Duration(int hour, int min, int sec) {
        this.hour = hour;
        this.min = min;
        this.sec = sec;
    }

    // 4. 一参构造器，总秒数int seconds，对hour、min、sec进行初始化
    public Duration(int seconds) {
        this.hour = seconds / 3600;
        this.min = (seconds % 3600) / 60;
        this.sec = seconds % 60;
    }

    // 5. 提供每个属性的get方法
    public int getHour() {
        return hour;
    }

    public int getMin() {
        return min;
    }

    public int getSec() {
        return sec;
    }

    // 6. getTotalSeconds()方法，用于返回总秒数seconds
    public int getTotalSeconds() {
        return hour * 3600 + min * 60 + sec;
    }

    // 7. display()方法，输出对象的属性信息和总秒数
    public void display() {
        System.out.println("Duration: " + hour + "小时" + min + "分钟" + sec + "秒");
        System.out.println("总秒数: " + getTotalSeconds());
    }
}